#!/bin/tcsh -ef
####
#
#############################################################################
#                                                                           #
# Title: Modify Image Amplitude                                             #
#                                                                           #
# (C) 2dx.org, GNU Plublic License.                                         #
#                                                                           #
# Created..........: 10/20/2007                                             #
# Last Modification: 10/20/2007                                             #
# Author...........: 2dx.org                                                #
#                                                                           #
#############################################################################
#
# SORTORDER: 80
#
# MANUAL: This script allows to multiply every pixel of the input image by a factor.
#
# MANUAL: If for example you have a 16-bit CCD camera that produces images with values up to 32000 or so, then you might run into problems with integer overflow in some of the MRC programs. 2dx_ttboxk, for example, is prone to that. In this case, it may be advised to simply downscale the pixels of the input image, using a factor of 0.1 or 0.01.
#
# MANUAL: If you copy the body of this script into the Initialization Script (which only runs once), then you can correct the image amplitudes for every image that you process.
#
# DISPLAY: imagename
# DISPLAY: nonmaskimagename
# DISPLAY: comment
# DISPLAY: down_factor
#
#$end_local_vars
#
set bin_2dx = ""
set proc_2dx = ""
#
set imagename = ""
set nonmaskimagename = ""
set down_factor = ""
#
#$end_vars
#
echo bin_2dx = ${bin_2dx}
echo proc_2dx = ${proc_2dx}
#
set scriptname = 2dx_ModifAmplitude
#
\rm -f LOGS/${scriptname}.results
#
source ${proc_2dx}/initialize
#
source ${proc_2dx}/2dx_makedirs 
#
echo "<<@progress: 1>>"
#
#############################################################################
${proc_2dx}/linblock "Multiplying pixels in ${imagename}.mrc by ${down_factor}"
#############################################################################  
#
\rm -f SCRATCH/${imagename}.mrc
#
${bin_2dx}/labelh.exe << eot
${imagename}.mrc
2
SCRATCH/${imagename}.mrc
${down_factor},0.0
0
eot
#
if ( -e SCRATCH/${imagename}.mrc ) then
  \mv -v SCRATCH/${imagename}.mrc ${imagename}.mrc
endif
#
\rm -f SCRATCH/${nonmaskimagename}.mrc
#
if ( ${nonmaskimagename} != ${imagename} ) then
  #
  #############################################################################
  ${proc_2dx}/linblock "Multiplying pixels in ${nonmaskimagename}.mrc by ${down_factor}"
  #############################################################################  
  #
  ${bin_2dx}/labelh.exe << eot
${nonmaskimagename}.mrc
2
SCRATCH/${nonmaskimagename}.mrc
${down_factor},0.0
0
eot
  #
  if ( -e SCRATCH/${nonmaskimagename}.mrc ) then
    \mv -v SCRATCH/${nonmaskimagename}.mrc ${nonmaskimagename}.mrc
  endif
  #
endif
#
echo "# IMAGE-IMPORTANT: ${imagename}.mrc <Downscaled image>" >> LOGS/${scriptname}.results
echo "# IMAGE-IMPORTANT: ${nonmaskimagename}.mrc <Downscaled non-masked image>" >> LOGS/${scriptname}.results
#
echo "<<@progress: 100>>"
#
##########################################################################
${proc_2dx}/linblock "${scriptname} - normal end."
##########################################################################
# 
